package com.xizi.leetcode周赛;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-8-29上午 11:39
 */
public class _5855_找出数组中的第K大整数 {
    public static void main(String[] args) {
        String[] num = new String[]{"3", "6", "7", "10"};
        final String s = kthLargestNumber(num, 2);
        System.out.println(s);
    }

    public static String kthLargestNumber(String[] nums, int k) {
        Arrays.sort(nums, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                if (o1.length() > o2.length()) {
                    return -1;
                } else if (o1.length() < o2.length()) {
                    return 1;
                } else {
                    for (int i = 0; i < o1.length(); i++) {
                        if (o1.charAt(i) > o2.charAt(i)) {
                            return -1;
                        } else {
                            return 1;
                        }
                    }
                }
                return 0;
            }
        });
        return nums[k - 1];
    }
}
